﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FileUtils;

namespace ResourceConverter
{
	public interface IResource : IComparable<IResource>, IComparable<string>
	{
		string Name { get; set;  }
		void Read ( Reader source, int size );
	}

	public abstract class Resource : IResource
	{
		public string Name { get; set; }

		public abstract void Read ( Reader source, int size );

		public int CompareTo ( IResource other )
		{
			return this.Name.CompareTo(other.Name);
		}

		public int CompareTo ( string other )
		{
			return this.Name.CompareTo(other);
		}
	}

	public class ResourcesUtils
	{
		public static readonly Color[] Palette = new Color[] {
            Color.FromArgb(0x00, 0x00, 0x00),
            Color.FromArgb(0x00, 0x00, 0xA8),
            Color.FromArgb(0x00, 0xA8, 0x00),
            Color.FromArgb(0x00, 0xA8, 0xA8),
            Color.FromArgb(0xA8, 0x00, 0x00),
            Color.FromArgb(0xA8, 0x00, 0xA8),
            Color.FromArgb(0xA8, 0x54, 0x00),
            Color.FromArgb(0xA8, 0xA8, 0xA8),
            Color.FromArgb(0x54, 0x54, 0x54),
            Color.FromArgb(0x54, 0x54, 0xFC),
            Color.FromArgb(0x54, 0xFC, 0x54),
            Color.FromArgb(0x54, 0xFC, 0xFC),
            Color.FromArgb(0xFC, 0x54, 0x54),
            Color.FromArgb(0xFC, 0x54, 0xFC),
            Color.FromArgb(0xFC, 0xFC, 0x54),
            Color.FromArgb(0xFC, 0xFC, 0xFC),
            Color.FromArgb(0xFC, 0xFC, 0xFC),
            Color.FromArgb(0xDC, 0xDC, 0xDC),
            Color.FromArgb(0xCC, 0xCC, 0xCC),
            Color.FromArgb(0xC0, 0xC0, 0xC0),
            Color.FromArgb(0xB0, 0xB0, 0xB0),
            Color.FromArgb(0xA4, 0xA4, 0xA4),
            Color.FromArgb(0x98, 0x98, 0x98),
            Color.FromArgb(0x88, 0x88, 0x88),
            Color.FromArgb(0x7C, 0x7C, 0x7C),
            Color.FromArgb(0x70, 0x70, 0x70),
            Color.FromArgb(0x60, 0x60, 0x60),
            Color.FromArgb(0x54, 0x54, 0x54),
            Color.FromArgb(0x48, 0x48, 0x48),
            Color.FromArgb(0x38, 0x38, 0x38),
            Color.FromArgb(0x2C, 0x2C, 0x2C),
            Color.FromArgb(0x20, 0x20, 0x20),
            Color.FromArgb(0xFC, 0xD8, 0xD8),
            Color.FromArgb(0xFC, 0xB8, 0xB8),
            Color.FromArgb(0xFC, 0x9C, 0x9C),
            Color.FromArgb(0xFC, 0x7C, 0x7C),
            Color.FromArgb(0xFC, 0x5C, 0x5C),
            Color.FromArgb(0xFC, 0x40, 0x40),
            Color.FromArgb(0xFC, 0x20, 0x20),
            Color.FromArgb(0xFC, 0x00, 0x00),
            Color.FromArgb(0xE4, 0x00, 0x00),
            Color.FromArgb(0xCC, 0x00, 0x00),
            Color.FromArgb(0xB4, 0x00, 0x00),
            Color.FromArgb(0x9C, 0x00, 0x00),
            Color.FromArgb(0x84, 0x00, 0x00),
            Color.FromArgb(0x70, 0x00, 0x00),
            Color.FromArgb(0x58, 0x00, 0x00),
            Color.FromArgb(0x40, 0x00, 0x00),
            Color.FromArgb(0xFC, 0xE8, 0xD8),
            Color.FromArgb(0xFC, 0xDC, 0xC0),
            Color.FromArgb(0xFC, 0xD4, 0xAC),
            Color.FromArgb(0xFC, 0xC8, 0x94),
            Color.FromArgb(0xFC, 0xC0, 0x80),
            Color.FromArgb(0xFC, 0xB8, 0x68),
            Color.FromArgb(0xFC, 0xAC, 0x54),
            Color.FromArgb(0xFC, 0xA4, 0x3C),
            Color.FromArgb(0xFC, 0x9C, 0x28),
            Color.FromArgb(0xE0, 0x88, 0x20),
            Color.FromArgb(0xC4, 0x78, 0x1C),
            Color.FromArgb(0xA8, 0x64, 0x14),
            Color.FromArgb(0x90, 0x54, 0x10),
            Color.FromArgb(0x74, 0x40, 0x08),
            Color.FromArgb(0x58, 0x30, 0x04),
            Color.FromArgb(0x40, 0x20, 0x00),
            Color.FromArgb(0xFC, 0xFC, 0xD8),
            Color.FromArgb(0xFC, 0xFC, 0xB8),
            Color.FromArgb(0xFC, 0xFC, 0x9C),
            Color.FromArgb(0xFC, 0xFC, 0x7C),
            Color.FromArgb(0xFC, 0xF8, 0x5C),
            Color.FromArgb(0xFC, 0xF4, 0x40),
            Color.FromArgb(0xFC, 0xF4, 0x20),
            Color.FromArgb(0xFC, 0xF4, 0x00),
            Color.FromArgb(0xE4, 0xD8, 0x00),
            Color.FromArgb(0xCC, 0xC0, 0x00),
            Color.FromArgb(0xB4, 0xA4, 0x00),
            Color.FromArgb(0x9C, 0x8C, 0x00),
            Color.FromArgb(0x84, 0x74, 0x00),
            Color.FromArgb(0x6C, 0x58, 0x00),
            Color.FromArgb(0x54, 0x40, 0x00),
            Color.FromArgb(0x40, 0x28, 0x00),
            Color.FromArgb(0xF8, 0xFC, 0xD8),
            Color.FromArgb(0xF4, 0xFC, 0xB8),
            Color.FromArgb(0xE8, 0xFC, 0x9C),
            Color.FromArgb(0xE0, 0xFC, 0x7C),
            Color.FromArgb(0xD0, 0xFC, 0x5C),
            Color.FromArgb(0xC4, 0xFC, 0x40),
            Color.FromArgb(0xB4, 0xFC, 0x20),
            Color.FromArgb(0xA0, 0xFC, 0x00),
            Color.FromArgb(0x90, 0xE4, 0x00),
            Color.FromArgb(0x80, 0xCC, 0x00),
            Color.FromArgb(0x74, 0xB4, 0x00),
            Color.FromArgb(0x60, 0x9C, 0x00),
            Color.FromArgb(0x50, 0x84, 0x00),
            Color.FromArgb(0x44, 0x70, 0x00),
            Color.FromArgb(0x34, 0x58, 0x00),
            Color.FromArgb(0x28, 0x40, 0x00),
            Color.FromArgb(0xD8, 0xFC, 0xD8),
            Color.FromArgb(0x9C, 0xFC, 0x9C),
            Color.FromArgb(0x90, 0xEC, 0x90),
            Color.FromArgb(0x84, 0xE0, 0x84),
            Color.FromArgb(0x78, 0xD0, 0x78),
            Color.FromArgb(0x70, 0xC4, 0x6C),
            Color.FromArgb(0x64, 0xB8, 0x64),
            Color.FromArgb(0x58, 0xA8, 0x58),
            Color.FromArgb(0x50, 0x9C, 0x4C),
            Color.FromArgb(0x44, 0x90, 0x40),
            Color.FromArgb(0x38, 0x80, 0x34),
            Color.FromArgb(0x2C, 0x74, 0x2C),
            Color.FromArgb(0x24, 0x68, 0x20),
            Color.FromArgb(0x18, 0x58, 0x14),
            Color.FromArgb(0x0C, 0x4C, 0x08),
            Color.FromArgb(0x04, 0x40, 0x00),
            Color.FromArgb(0xD8, 0xFC, 0xFC),
            Color.FromArgb(0xB8, 0xFC, 0xFC),
            Color.FromArgb(0x9C, 0xFC, 0xFC),
            Color.FromArgb(0x7C, 0xFC, 0xF8),
            Color.FromArgb(0x5C, 0xFC, 0xFC),
            Color.FromArgb(0x40, 0xFC, 0xFC),
            Color.FromArgb(0x20, 0xFC, 0xFC),
            Color.FromArgb(0x00, 0xFC, 0xFC),
            Color.FromArgb(0x00, 0xE4, 0xE4),
            Color.FromArgb(0x00, 0xCC, 0xCC),
            Color.FromArgb(0x00, 0xB4, 0xB4),
            Color.FromArgb(0x00, 0x9C, 0x9C),
            Color.FromArgb(0x00, 0x84, 0x84),
            Color.FromArgb(0x00, 0x70, 0x70),
            Color.FromArgb(0x00, 0x58, 0x58),
            Color.FromArgb(0x00, 0x40, 0x40),
            Color.FromArgb(0xD8, 0xEC, 0xFC),
            Color.FromArgb(0xB8, 0xE0, 0xFC),
            Color.FromArgb(0x9C, 0xD4, 0xFC),
            Color.FromArgb(0x7C, 0xC8, 0xFC),
            Color.FromArgb(0x5C, 0xBC, 0xFC),
            Color.FromArgb(0x40, 0xB0, 0xFC),
            Color.FromArgb(0x00, 0x9C, 0xFC),
            Color.FromArgb(0x00, 0x8C, 0xE4),
            Color.FromArgb(0x00, 0x80, 0xD0),
            Color.FromArgb(0x00, 0x74, 0xBC),
            Color.FromArgb(0x00, 0x64, 0xA8),
            Color.FromArgb(0x00, 0x58, 0x90),
            Color.FromArgb(0x00, 0x4C, 0x7C),
            Color.FromArgb(0x00, 0x3C, 0x68),
            Color.FromArgb(0x00, 0x30, 0x54),
            Color.FromArgb(0x00, 0x24, 0x40),
            Color.FromArgb(0xD8, 0xD8, 0xFC),
            Color.FromArgb(0xB8, 0xBC, 0xFC),
            Color.FromArgb(0x9C, 0x9C, 0xFC),
            Color.FromArgb(0x7C, 0x80, 0xFC),
            Color.FromArgb(0x5C, 0x60, 0xFC),
            Color.FromArgb(0x40, 0x40, 0xFC),
            Color.FromArgb(0x00, 0x04, 0xFC),
            Color.FromArgb(0x00, 0x00, 0xE4),
            Color.FromArgb(0x00, 0x00, 0xD0),
            Color.FromArgb(0x00, 0x00, 0xBC),
            Color.FromArgb(0x00, 0x00, 0xA8),
            Color.FromArgb(0x00, 0x00, 0x90),
            Color.FromArgb(0x00, 0x00, 0x7C),
            Color.FromArgb(0x00, 0x00, 0x68),
            Color.FromArgb(0x00, 0x00, 0x54),
            Color.FromArgb(0x00, 0x00, 0x40),
            Color.FromArgb(0xF0, 0xD8, 0xFC),
            Color.FromArgb(0xE4, 0xB8, 0xFC),
            Color.FromArgb(0xD8, 0x9C, 0xFC),
            Color.FromArgb(0xD0, 0x7C, 0xFC),
            Color.FromArgb(0xC8, 0x5C, 0xFC),
            Color.FromArgb(0xBC, 0x40, 0xFC),
            Color.FromArgb(0xB4, 0x20, 0xFC),
            Color.FromArgb(0xA8, 0x00, 0xFC),
            Color.FromArgb(0x98, 0x00, 0xE4),
            Color.FromArgb(0x80, 0x00, 0xCC),
            Color.FromArgb(0x74, 0x00, 0xB4),
            Color.FromArgb(0x60, 0x00, 0x9C),
            Color.FromArgb(0x50, 0x00, 0x84),
            Color.FromArgb(0x44, 0x00, 0x70),
            Color.FromArgb(0x34, 0x00, 0x58),
            Color.FromArgb(0x28, 0x00, 0x40),
            Color.FromArgb(0xFC, 0xD8, 0xFC),
            Color.FromArgb(0xFC, 0xB8, 0xFC),
            Color.FromArgb(0xFC, 0x9C, 0xFC),
            Color.FromArgb(0xFC, 0x7C, 0xFC),
            Color.FromArgb(0xFC, 0x5C, 0xFC),
            Color.FromArgb(0xFC, 0x40, 0xFC),
            Color.FromArgb(0xFC, 0x20, 0xFC),
            Color.FromArgb(0xE0, 0x00, 0xE4),
            Color.FromArgb(0xCC, 0x00, 0xCC),
            Color.FromArgb(0xB8, 0x00, 0xB8),
            Color.FromArgb(0xA4, 0x00, 0xA4),
            Color.FromArgb(0x90, 0x00, 0x90),
            Color.FromArgb(0x7C, 0x00, 0x7C),
            Color.FromArgb(0x68, 0x00, 0x68),
            Color.FromArgb(0x54, 0x00, 0x54),
            Color.FromArgb(0x40, 0x00, 0x40),
            Color.FromArgb(0xFC, 0xE8, 0xDC),
            Color.FromArgb(0xF0, 0xD4, 0xC4),
            Color.FromArgb(0xE4, 0xC4, 0xAC),
            Color.FromArgb(0xD8, 0xB4, 0x98),
            Color.FromArgb(0xCC, 0xA0, 0x80),
            Color.FromArgb(0xC0, 0x90, 0x6C),
            Color.FromArgb(0xB4, 0x80, 0x54),
            Color.FromArgb(0xAC, 0x70, 0x40),
            Color.FromArgb(0x9C, 0x64, 0x38),
            Color.FromArgb(0x8C, 0x5C, 0x34),
            Color.FromArgb(0x80, 0x54, 0x2C),
            Color.FromArgb(0x70, 0x4C, 0x28),
            Color.FromArgb(0x60, 0x40, 0x20),
            Color.FromArgb(0x54, 0x38, 0x1C),
            Color.FromArgb(0x44, 0x30, 0x14),
            Color.FromArgb(0x38, 0x28, 0x10),
            Color.FromArgb(0xFC, 0xD8, 0xCC),
            Color.FromArgb(0xF8, 0xCC, 0xB8),
            Color.FromArgb(0xF4, 0xC0, 0xA8),
            Color.FromArgb(0xF0, 0xB4, 0x94),
            Color.FromArgb(0xEC, 0xA8, 0x84),
            Color.FromArgb(0xE8, 0x9C, 0x74),
            Color.FromArgb(0xE4, 0x94, 0x64),
            Color.FromArgb(0xE0, 0x8C, 0x58),
            Color.FromArgb(0xD8, 0x80, 0x4C),
            Color.FromArgb(0xD4, 0x78, 0x40),
            Color.FromArgb(0xC8, 0x6C, 0x34),
            Color.FromArgb(0xC0, 0x60, 0x2C),
            Color.FromArgb(0xB4, 0x54, 0x24),
            Color.FromArgb(0xA8, 0x48, 0x1C),
            Color.FromArgb(0x9C, 0x3C, 0x14),
            Color.FromArgb(0x94, 0x30, 0x0C),
            Color.FromArgb(0xF4, 0xC0, 0xA8),
            Color.FromArgb(0xF0, 0xBC, 0xA0),
            Color.FromArgb(0xF0, 0xB8, 0x9C),
            Color.FromArgb(0xF0, 0xB4, 0x94),
            Color.FromArgb(0xEC, 0xB0, 0x90),
            Color.FromArgb(0xEC, 0xAC, 0x88),
            Color.FromArgb(0xEC, 0xA8, 0x84),
            Color.FromArgb(0xE8, 0xA4, 0x80),
            Color.FromArgb(0xE8, 0xA0, 0x78),
            Color.FromArgb(0xE8, 0x9C, 0x74),
            Color.FromArgb(0xE4, 0x98, 0x6C),
            Color.FromArgb(0xE4, 0x94, 0x68),
            Color.FromArgb(0xE4, 0x94, 0x64),
            Color.FromArgb(0xFC, 0x9C, 0x9C),
            Color.FromArgb(0xFC, 0x94, 0x94),
            Color.FromArgb(0xFC, 0x90, 0x90),
            Color.FromArgb(0xFC, 0x8C, 0x8C),
            Color.FromArgb(0xFC, 0x84, 0x84),
            Color.FromArgb(0xFC, 0x80, 0x80),
            Color.FromArgb(0xFC, 0x7C, 0x7C),
            Color.FromArgb(0xD8, 0xB4, 0x98),
            Color.FromArgb(0xD0, 0xAC, 0x8C),
            Color.FromArgb(0xCC, 0xA4, 0x84),
            Color.FromArgb(0xC8, 0x9C, 0x7C),
            Color.FromArgb(0xC4, 0x94, 0x74),
            Color.FromArgb(0xC0, 0x90, 0x6C),
            Color.FromArgb(0xC0, 0xC0, 0xC0),
            Color.FromArgb(0xBC, 0xBC, 0xBC),
            Color.FromArgb(0xB8, 0xB8, 0xB8),
            Color.FromArgb(0xB4, 0xB4, 0xB4),
            Color.FromArgb(0xB0, 0xB0, 0xB0),
            Color.FromArgb(0x80, 0xFC, 0xFC, 0xFC)
		};
	}
}
